{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python \t\t3.6\n",
      "Tensorflow \t1.0.0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Keras \t\t2.0.3\n"
     ]
    }
   ],
   "source": [
    "import sys; print('Python \\t\\t{0[0]}.{0[1]}'.format(sys.version_info))\n",
    "import tensorflow as tf; print('Tensorflow \\t{}'.format(tf.__version__))\n",
    "import keras; print('Keras \\t\\t{}'.format(keras.__version__))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline \n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting ../mnist-data/train-images-idx3-ubyte.gz\n",
      "Extracting ../mnist-data/train-labels-idx1-ubyte.gz\n",
      "Extracting ../mnist-data/t10k-images-idx3-ubyte.gz\n",
      "Extracting ../mnist-data/t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "mnist = input_data.read_data_sets(\"../mnist-data/\", one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(55000, 784)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mnist.train.images.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA2oAAABpCAYAAABLV9A4A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G+\n709/+hMAzrnKDkxEas5dd90FwOjRo33fpEmTANhxxx2rMiYRadp3330HwI033uj7Xnklt+bBs88+\n69vbb7903962bdv6Pnvet2nTxvd16NAh7mBbmbvvXlok8NJLL/V9VtxN2Uo5rLfeejl977zzThVG\nUhzNqImIiIiIiKSMDtRERERERERSpsUtfbz88st9e6WVVgJgzJgxvm+FFVrcXa66N954A4ARI0b4\nvrffftu3bfnJxx9/7PvuvfdeAM477zzf16lTp7KOU6S57rjjDgDmzp3r++xxPnv27KqMSaS1C09x\nWLhwIQB/+ctffN9hhx0GwNChQ5u8nh122MG3J06cCEBdXZ3vmzZtGgCzZs3yfccddxwAxx9/vO+z\nzxqS3zPPPOPbw4YNA2CfffbxfSuuuGKlhyStyLx58wBYd911qzyS4mhGTUREREREJGVa3PSSFQsB\nOOqoo4Dsb8gkjldffdW3Bw0aBGSfnJkkiW8PGDAAgI022sj32WzEzJkzfd/DDz8MQMeOHcsw4vSy\nb4TXXHNN32czv4sXL/Z9H3zwQc7vPv7447793HPPNXobV111lW+vvfbaOZf/+c9/BmC//fYrdNit\nwvTp06s9hKr47LPPAPjDH/7g+8IZi6b8+Mc/9u2LL74YgPXXXz/i6KQ1+fzzz33b3jfOPPNM3zd5\n8uSc37nkkksA6Nu3r++zWba33nrL92222Wa+bbNrW265pe974oknADj88MN9n82yLViwwPddcMEF\ngGbWlnXfffcBcMUVV/i+//znPwCstdZavq+15vbRRx8Bmc8+AOPGjQOyt5AK/fa3vwVg/PjxZR5d\nbbMCNZB5btvztDnComFWoND+BpWiGTUREREREZGU0YGaiIiIiIhIyrSYpY92cvHXX3/t+3r27Fmt\n4bRYJ554IgCPPvqo77Mlj127dvV94TK+F198EYAjjzzS99mJ23YZwI9+9CMgs7QEYOWVV4429mqx\n+wrZSxzMY489BmRPsdtSEFsaEf5cKFxi2tTegOHPvfnmmzmX2xKftC99vPXWWwG4+eabfd9ZZ50F\nQK9evSoyBltC1dI89dRTvj1y5EgAXnvtNd+X7/G10047AfD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oVSbLkoLK2m1BjbGw1gn332AbC14TlseWh4Yvzll19e/GDzSGOm5WTFgsJlz2HR\nghhaW6aFsiW6TT0/mpIn117OucG0klz32GOP6NdZjUw7dOjg22effTaQWRIfOvHETP0CWwYZFqGy\nolhhAbCLL74YgB133NH3hUUECl0mHr6eN9eymb7xxhuk8XFqS5DDPezs72GFKyCzNN/er6qhtb2m\nWhGmr776yveFf5MYWkOm8+bNy2mntahIIVUfnwIaK3kW/92hFejXr19OxTPn3KdJknyEMi2KMo1P\nmcanTMtj2Vydc7OTJLFvgZRrEZRpfMtm2qdPH2bMmKFMS6DX1PiUaboU9/WltFjhSen2rWV40qqV\nLp4/f77vs4ILYeGL8Elu31RaoRaAX//610Bps2hpN3bsWACeffZZ3zdgwAAAFixY4Pvsm+B7773X\n933xxRdAdll4m7mETGGWfv36xR52q7fLLrv49qOPPgpkzyBLfEuWLAHgu+8y56vHKNjUUoQFMJ54\n4gkANt10U99X6nYpadGmTRvftvef8D3i7bffBjLbuwBssMEGOT9n70XhY2jFFVcsw4hbJsvK3sMg\n8xgMi6hUcyatNendu7dvT5s2rYojqW077LCDb4efYdNO74QiIiIiIiIpowM1ERERERGRlNHSR2lU\nx44dAZgwYYLvs7YtvwFs086swgvhMkc7GTU8ibs12GSTTYDs5SO2ZCdc0pjPyiuvDGTvaxdeTyl7\nzUnThg0blrctcay11lo5fVOnTgWy9wvacMMNKzWk1Hv55Zd924oIhEsfiy3Ckma2DHLQoEE5lx19\n9NGVHk6rd9FFF1V7CK1W+Fw39vkMYP3116/kcGrW008/Xe0hFEUzaiIiIiIiIinT8r6Gk4ro379/\nTt/AgQOrMJL0uuyyy4BMqWOAe+65B8guu28zb4MHD/Z9Y8aMAaCurq7cwxSpqAsvvBCA+vp639ej\nRw8gveWRq+2FF17I6cs30yQiLc/BBx/s29dccw0AZ511lu/beOONKz4mqRzNqImIiIiIiKSMDtRE\nRERERERSRksfRcqkXbt2AJx++um+L2yLtEYdOnQAMnvUSfNYkZWRI0d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y+ac84B1wCvJklyQXDR3cDQ\nhvZQ4B8VHpoyjU+ZxlezmUJqc1Wm8SnT+JRpfMq0PGo2V2UaX6oyjVWVpJD/gMEsrZwyBzilkrdd\n4rj7sXR680XghYb/BgNrAo8AbwIPA2tUYWzKVJkq01aYqzJVpspUmSpT5apMW3amrmFAIiIiIiIi\nkhIqJiIiIiIiIpIyOlATERERERFJGR2oiYiIiIiIpIwO1ERERERERFJGB2oiIiIiIiIpowM1ERER\nERGRlNGBmoiIiIiISMr8PzT+1wrcrWcKAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1180a4588>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15,5))\n",
    "for i in list(range(10)):\n",
    "    plt.subplot(1, 10, i+1)\n",
    "    pixels = mnist.test.images[i+100]\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers.core import Dense, Activation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model = Sequential()\n",
    "model.add(Dense(10, input_shape=(784,)))\n",
    "model.add(Activation('softmax'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 55000 samples, validate on 10000 samples\n",
      "Epoch 1/10\n",
      "55000/55000 [==============================] - 0s - loss: 1.1687 - acc: 0.7100 - val_loss: 0.6501 - val_acc: 0.8579\n",
      "Epoch 2/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.5654 - acc: 0.8641 - val_loss: 0.4656 - val_acc: 0.8889\n",
      "Epoch 3/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.4512 - acc: 0.8851 - val_loss: 0.3969 - val_acc: 0.9005\n",
      "Epoch 4/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3989 - acc: 0.8953 - val_loss: 0.3615 - val_acc: 0.9054\n",
      "Epoch 5/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3683 - acc: 0.9019 - val_loss: 0.3386 - val_acc: 0.9101\n",
      "Epoch 6/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3478 - acc: 0.9067 - val_loss: 0.3233 - val_acc: 0.9118\n",
      "Epoch 7/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3329 - acc: 0.9103 - val_loss: 0.3133 - val_acc: 0.9135\n",
      "Epoch 8/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3216 - acc: 0.9126 - val_loss: 0.3032 - val_acc: 0.9155\n",
      "Epoch 9/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3131 - acc: 0.9146 - val_loss: 0.2968 - val_acc: 0.9161\n",
      "Epoch 10/10\n",
      "55000/55000 [==============================] - 0s - loss: 0.3055 - acc: 0.9161 - val_loss: 0.2929 - val_acc: 0.9186\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x121e32e80>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(mnist.train.images, mnist.train.labels,\n",
    "          batch_size=500, epochs=10, verbose=1,\n",
    "          validation_data=(mnist.test.images, mnist.test.labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test score: 0.292889834046\n",
      "Test accuracy: 0.9186\n"
     ]
    }
   ],
   "source": [
    "score = model.evaluate(mnist.test.images, mnist.test.labels, verbose=0)\n",
    "print('Test score:', score[0])\n",
    "print('Test accuracy:', score[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 0.0038107741,\n",
       " 1: 0.0036255594,\n",
       " 2: 0.068874724,\n",
       " 3: 0.0040754587,\n",
       " 4: 0.0050108018,\n",
       " 5: 0.00063145149,\n",
       " 6: 0.90202528,\n",
       " 7: 0.00082349818,\n",
       " 8: 0.00834422,\n",
       " 9: 0.0027782677}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# test item #100 is a six\n",
    "pixels = mnist.test.images[100]\n",
    "result = model.predict_on_batch(np.array([pixels]))\n",
    "dict(zip(range(10), result[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def test_render(pixels, result, truth):\n",
    "    #pixels, result and truth are np vectors\n",
    "    plt.figure(figsize=(10,5))\n",
    "    plt.subplot(1, 2, 1)\n",
    "    pixels = pixels.reshape((28, 28))\n",
    "    plt.imshow(pixels, cmap='gray_r')\n",
    "\n",
    "    plt.subplot(1, 2, 2)\n",
    "    \n",
    "    #index, witdh\n",
    "    ind = np.arange(len(result))\n",
    "    width = 0.49\n",
    "\n",
    "    plt.barh(ind,result, width, color='orange', edgecolor='k', hatch=\"/\")\n",
    "    plt.barh(ind+width,truth,width, color='g', edgecolor='k')\n",
    "    plt.yticks(ind+width, range(10))\n",
    "    plt.margins(y=0)\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAEyCAYAAADeAVWKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHYhJREFUeJz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iGm2artGXzU9r+PiFeTpsrvUkm3RcQ3bZ8u6W9t\nn1Rf9LctsWcKAN6T5+oM787YHqPaYY6XWpIuW66rS9j+uKTrJZ0fEW+1KFteWT/D4ZJOkrTK9iZJ\np0laWaKT0PP8N9gqaWVEvB0R/yLpOdXKVRnkyX+5amvpKSJ+Iel9qq0RWBVNvwoLZQoA3pPn6gyN\nK9xfJOmfozwL9mXmt32KpO+pVqTKdK7OPsP+DBGxKyImRsT0iJiu2nlf50dEb5q4/0qeP0P/oNpe\nKdmeqNphv42tDDmMPPk3S5ojSbZPVK1M7WxpymJWSvrT+qf6TpO0q+gixRzmA4C6iHjH9pWSHtB7\nV2d4xvZNknojYqVql+P5W9sbVDvJ9ZJ0if9QzvxflzRe0vL6efObI+L8ZKEHyfkzlFbO/A9IOtf2\nOkn9kv5rRJRi72bO/NdK+r7ta1Q7Gf1zJfoHxR9cUaN+XtcNksZKUkT8L9XO85onaYOkNyQtLPyc\nJfr5AQAAKofDfAAAAAVQpgAAAAqgTAEAABRAmQIAACiAMgUAAFAAZQoAAKAAyhQAAEAB/x8D5CaR\nGRUgDgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x121f10eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import random\n",
    "i = random.randint(0,mnist.test.images.shape[0])\n",
    "\n",
    "pixels = mnist.test.images[i]\n",
    "truth  = mnist.test.labels[i]\n",
    "result = model.predict_on_batch(np.array([pixels]))[0]\n",
    "\n",
    "test_render(pixels, result, truth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
